//
//  FriendCell.m
//  NewPro
//
//  Created by 何荧红 on 2018/10/7.
//  Copyright © 2018 何荧红. All rights reserved.
//

#import "FriendCell.h"
#import "FriendModel.h"
#import "FriendList.h"
#import "CurrTransModel.h"

@interface FriendCell ()
{
    
    __weak IBOutlet UIImageView *headerIm;
    __weak IBOutlet UILabel *nameLa;
    
    __weak IBOutlet UILabel *desLa;
    
    __weak IBOutlet UIImageView *leveIm;
}


@end

@implementation FriendCell


+ (instancetype)tempWithTableView:(UITableView *)tableView{
    
    NSString *identity = @"CELL";
    NSInteger index = 0;
    

    ClassName
    FriendCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
    
    if (!cell) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] objectAtIndex:index];
    }
    
    return cell;
}

+ (CGFloat)getHeight{
    
    UITableViewCell *cell = [self cell];
    return cell.frame.size.height;
}

+ (instancetype)cell{
    
    ClassName
    
    FriendCell *cell = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] objectAtIndex:0];
    return cell;
}

- (void)reviveInfoWithModel:(FriendModel *)model andFlag:(NSInteger)flag andType:(NSInteger)type{
    
    [headerIm sd_setImageWithURL:[NSURL URLWithString:model.headImg] placeholderImage:[UIImage imageNamed:@"头像"]];
    nameLa.text = model.realName;
    
    desLa.alpha = 1;
    
    if (flag == 1) {
        
        desLa.alpha = 0;
        leveIm.alpha = 0;
    }
    
    CurrTransModel *cmodel = model.currTrans;
    
    if (type == 0) {
        
        desLa.alpha = 0;
    }else if (type == 1){
        
        desLa.text = [NSString stringWithFormat:@"共%@位合伙人",model.allyCount];
        if (model.allyCount.length <= 0) {
            
            desLa.text = [NSString stringWithFormat:@"共0位合伙人"];
        }
        
    }else if (type == 2){
        
        desLa.text = [NSString stringWithFormat:@"%.2f万元",cmodel.totalAmount];
        if (cmodel.totalAmount <= 0) {
            
            desLa.text = [NSString stringWithFormat:@"0万元"];
        }
        
    }else if (type == 3){
        
        desLa.text = [NSString stringWithFormat:@"激活%@户",model.merchantCount];
        if (model.merchantCount.length <= 0) {
            
            desLa.text = [NSString stringWithFormat:@"激活0户"];
        }
    }
    
    NSString *img = [NSString stringWithFormat:@"等级%ld",(long)[cmodel.levelAmount integerValue]];
    leveIm.image = [UIImage imageNamed:img];
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
